package com.wct.spzx.manager.config;

import com.wct.spzx.manager.interceptor.LoginAuthInterceptor;
import com.wct.spzx.manager.properties.UserProperties;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Administrator
 */
@Component
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Resource
    private UserProperties userProperties;

    @Resource
    private LoginAuthInterceptor loginAuthInterceptor;
    /**
     * 跨域配置
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 路径规则
        registry.addMapping("/**")
                // 允许传递Cookie
                .allowCredentials(true)
                // 来源
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("*");

    }

    /**
     * 拦截器注册
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginAuthInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(userProperties.getNoAuthUrls());
/*                .excludePathPatterns("/admin/system/index/login",
                        "/admin/system/index/generateValidateCode",
                        "/admin/system/index/getPublicKey");*/
    }
}
